home *** CD-ROM | disk | FTP | other *** search
/ Maclife 42 / MACLIFE42.ISO.7z / MACLIFE42.ISO / FreeWare200 / 圧縮伸張⁄コード / MacGzip / MacGzip 1.1.2 Source.sea / MacGzip 1.1.2 Source / Mac / PrefsDlg.c < prev    next >
Text File  |  1997-04-01  |  23KB  |  883 lines

  1. /*
  2.  * PrefsDlg.c
  3.  * (C) SPDsoft, August 13, 1995
  4.  *
  5.  * Prefs Dialog
  6.  */
  7.  
  8. /*
  9.  * THINK_C 8.0 extra includes (Not in MacHeaders)
  10.  */
  11.  
  12. #include <Balloons.h>
  13. #include <Aliases.h>
  14.  
  15.  
  16. #include "GzErrors.h"
  17. #include "ErrorStrings.h"
  18. #include "GzPStrings.h"
  19.  
  20. #include "PrefsDlg.h"
  21. #include "Prefs.h"
  22.  
  23. #include "tailor.h" /* for MAX_SUFFIX */
  24.  
  25. /*
  26.  * Globals
  27.  */
  28.  
  29. AliasHandle gOriginalAliasHdl;
  30.  
  31. /*
  32.  * Prototypes
  33.  */
  34.  
  35. Boolean DoPrefsDialog(PrefsTypePtr thePrefs, AliasHandle * theFldrAlias);
  36.  
  37. static void DoItem(    DialogPtr DlgPtr, short item,
  38.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs, AliasHandle *FldrAlias );
  39. static void SetItems(    DialogPtr DlgPtr,
  40.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs, AliasHandle *FldrAlias );
  41.                     
  42. static Boolean GetItems(    DialogPtr DlgPtr,
  43.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs );
  44.  
  45. static void SetUpDitl(    DialogPtr DlgPtr, DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs );
  46. static void CleanDitl(    DialogPtr DlgPtr, DlgInfoPtr myDlgInfo );
  47.  
  48. static Boolean GetItemValue( DialogPtr DlgPtr, short item, short *value);
  49. static void SetItemValue( DialogPtr DlgPtr, short item, short value);
  50. static void SetItemText( DialogPtr DlgPtr, short item, Str255 pstr, Boolean quote);
  51. static void DisableDItem( DialogPtr DlgPtr, short item);
  52. static void EnableDItem( DialogPtr DlgPtr, short item);
  53.  
  54. /*
  55.  * main function
  56.  */
  57.  
  58. Boolean DoPrefsDialog(PrefsTypePtr thePrefs, AliasHandle * theFldrAlias)
  59. {
  60.     GrafPtr                savePort;
  61.     DialogPtr            DlgPtr;
  62.     short                itemHit;
  63.     Boolean                DlgDone;
  64.     Boolean                SaveBalloons;
  65.     ModalFilterUPP        ModalUPP;
  66.  
  67.     Boolean                result = false;
  68.     PrefsType            tmpPrefs;        /* work on these */
  69.     AliasHandle            FldrAlias;        /* instead of originals */
  70.     extern PrefsType    DefaultPrefs;
  71.     
  72.     static DlgInfo myDlgInfo =
  73.         {
  74.             {
  75.                 kPrefgzipDITL_ID,
  76.                 kPrefCompDITL_ID,
  77.                 kPrefDecoDITL_ID,
  78.                 kPrefFoldDITL_ID,
  79.                 kPrefMiscDITL_ID
  80.             },
  81.             0,                            /* Number of items in layout DITL */
  82.             pmPrefgzip
  83.         };
  84.     
  85.     if ( nil == (DlgPtr = GetNewDialog(kPrefGenPDLOG_ID, nil, (WindowPtr) -1)))
  86.     {
  87.         if ( noErr == (err = ResError())) err = resFNotFound;
  88.         DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
  89.     }
  90.     
  91.     BlockMove(thePrefs, &tmpPrefs, sizeof(tmpPrefs));
  92.     gOriginalAliasHdl = *theFldrAlias;
  93.     FldrAlias = *theFldrAlias;
  94.     
  95.     GetPort(&savePort);
  96.     SetPort(DlgPtr);
  97.     
  98.     SetDialogDefaultItem( DlgPtr, kPrefComm_OK_ID);
  99.     SetDialogCancelItem( DlgPtr, kPrefComm_Cancel_ID);
  100.     
  101.     if (noErr != (err = GetStdFilterProc(&ModalUPP)) )
  102.     {
  103.         DoError(SYS_ERR,QUIT_ERR,GetErrFmt(GENERIC, NOT_UPP), 1);
  104.     }
  105.     
  106.     myDlgInfo.BaseDITL = CountDITL( DlgPtr );
  107.     SetItemValue( DlgPtr, kPrefComm_Menu_ID, myDlgInfo.Selection );
  108.     SetUpDitl( DlgPtr, &myDlgInfo, &tmpPrefs);
  109.     SetItems( DlgPtr, &myDlgInfo, &tmpPrefs,  &FldrAlias);
  110.     
  111.     /*
  112.      * Initial Dlg values
  113.      */
  114.      
  115.     SaveBalloons = HMGetBalloons();
  116.     SetItemValue( DlgPtr, kPrefComm_Help_ID, (short) SaveBalloons );
  117.  
  118.     for( DlgDone = FALSE; !DlgDone ; )
  119.     {
  120.         ModalDialog(ModalUPP, &itemHit);
  121.         
  122.         switch ( itemHit )
  123.         {
  124.             case kPrefComm_OK_ID:
  125.                 
  126.                 /*
  127.                  * Save Dlg Prefs
  128.                  */
  129.                 if (GetItems( DlgPtr, &myDlgInfo, &tmpPrefs ))
  130.                 {
  131.                     BlockMove(&tmpPrefs, thePrefs, sizeof(tmpPrefs));
  132.                     
  133.                     if (*theFldrAlias != FldrAlias)
  134.                     {
  135.                         if (*theFldrAlias != nil)
  136.                             DisposeHandle((Handle)  *theFldrAlias);
  137.                             
  138.                         *theFldrAlias = FldrAlias;
  139.                     }
  140.                     DlgDone = TRUE;
  141.                     result = TRUE;
  142.                 }
  143.                 break;
  144.                 
  145.             case kPrefComm_Cancel_ID:
  146.                 
  147.                 /*
  148.                  * Discard Dlg Prefs
  149.                  */
  150.                  
  151.                 DlgDone = TRUE;
  152.                 break;
  153.                 
  154.             case kPrefComm_Dflt_ID:
  155.                 
  156.                 /*
  157.                  * Set Defaults
  158.                  */
  159.                 switch( myDlgInfo.Selection )
  160.                 {
  161.                     case pmPrefgzip:
  162.                             BlockMove(& DefaultPrefs.gzip, & tmpPrefs.gzip, sizeof(gzip_prefs));
  163.                         break;
  164.                         
  165.                     case pmPrefcomp:
  166.                             BlockMove(& DefaultPrefs.Compress, & tmpPrefs.Compress, sizeof(Compress_prefs));
  167.                         break;
  168.                         
  169.                     case pmPrefdeco:
  170.                             BlockMove(& DefaultPrefs.Decompress, & tmpPrefs.Decompress, sizeof(Decompress_prefs));
  171.                         break;
  172.                         
  173.                     case pmPreffold:
  174.                             BlockMove(& DefaultPrefs.Folder, & tmpPrefs.Folder, sizeof(Folder_prefs));
  175.                         break;
  176.                         
  177.                     case pmPrefmisc:
  178.                             BlockMove(& DefaultPrefs.Misc, & tmpPrefs.Misc, sizeof(Misc_prefs));
  179.                         break;
  180.                         
  181.                     default:
  182.                         break;
  183.                 }        
  184.                  SetItems( DlgPtr, &myDlgInfo, &tmpPrefs, &FldrAlias );
  185.                  
  186.                 break;
  187.                 
  188.             case kPrefComm_Help_ID:
  189.                 
  190.                 /*
  191.                  * Balloon Help on/off
  192.                  */
  193.                 HMSetBalloons(!HMGetBalloons());
  194.                 SetItemValue( DlgPtr, kPrefComm_Help_ID, (short) HMGetBalloons() );
  195.  
  196.                 break;
  197.                 
  198.             case kPrefComm_Menu_ID:
  199.                 
  200.                 /*
  201.                  * Change DITL
  202.                  */
  203.                 if (GetItems( DlgPtr, &myDlgInfo, &tmpPrefs ))
  204.                 { 
  205.                     if ( GetItemValue( DlgPtr, kPrefComm_Menu_ID, &(myDlgInfo.Selection)))
  206.                     {
  207.                         CleanDitl(DlgPtr, &myDlgInfo);
  208.                         SetUpDitl(DlgPtr, &myDlgInfo, &tmpPrefs);
  209.                         SetItems( DlgPtr, &myDlgInfo, &tmpPrefs, &FldrAlias );
  210.                     }
  211.                 }
  212.                 else
  213.                     SetItemValue( DlgPtr, kPrefComm_Menu_ID, myDlgInfo.Selection);
  214.                     
  215.                 break;
  216.             
  217.             default:
  218.                 
  219.                 DoItem(    DlgPtr, itemHit, &myDlgInfo, &tmpPrefs, &FldrAlias );
  220.                 break;
  221.         }
  222.                 
  223.     }
  224.     
  225.     HMSetBalloons(SaveBalloons);
  226.     
  227.     SetPort(savePort);
  228.     DisposeRoutineDescriptor (ModalUPP);
  229.     DisposeDialog(DlgPtr);
  230.     return result;
  231. }
  232.  
  233.  
  234. /*
  235.  * Manage extra DITL's
  236.  */
  237.  
  238. static void SetUpDitl(    DialogPtr DlgPtr, DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs )
  239. {
  240. #pragma unused(thePrefs)
  241.  
  242.     Handle        addDitl;
  243.  
  244.     if (nil == (addDitl =
  245.         GetResource( 'DITL', myDlgInfo->ExtraDITL[myDlgInfo->Selection - 1]   )))
  246.     {
  247.         if ( noErr == (err = ResError())) err = resFNotFound;
  248.         DoError(SYS_ERR,QUIT_ERR,GetErrFmt(RES_MANAGER, RES_NOTFOUND));
  249.     }
  250.     
  251.     HLock( addDitl );
  252.     AppendDITL( DlgPtr, addDitl, myDlgInfo->BaseDITL );
  253.     HUnlock( addDitl );
  254.     ReleaseResource( addDitl );
  255.  
  256. }
  257.  
  258. static void CleanDitl(    DialogPtr DlgPtr, DlgInfoPtr myDlgInfo )
  259. {
  260.     ShortenDITL( DlgPtr, CountDITL( DlgPtr ) - myDlgInfo->BaseDITL );
  261. }
  262.  
  263. /*
  264.  * Set/get values for controls (access by Item ID)
  265.  */
  266.  
  267. static Boolean GetItemValue( DialogPtr DlgPtr, short item, short *value)
  268. {
  269.     short        itemType;
  270.     Handle        itemHandle;
  271.     Rect        itemRect;
  272.     short        newValue;
  273.  
  274.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  275.     newValue = GetControlValue( (ControlHandle)itemHandle);
  276.     
  277.     if ( *value == newValue )
  278.         return FALSE;
  279.     else
  280.     {
  281.         *value = newValue;
  282.         return TRUE;
  283.     }
  284. }
  285.  
  286. static void SetItemValue( DialogPtr DlgPtr, short item, short value)
  287. {
  288.     short        itemType;
  289.     Handle        itemHandle;
  290.     Rect        itemRect;
  291.  
  292.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  293.     SetControlValue( (ControlHandle) itemHandle, value );
  294. }
  295.  
  296. static void SetItemText( DialogPtr DlgPtr, short item, Str255 pstr, Boolean quote)
  297. {
  298.     short        itemType;
  299.     Handle        itemHandle;
  300.     Rect        itemRect;
  301.     Str255        sTemp;
  302.  
  303.     if (quote)
  304.     {
  305.         sTemp[0] = 0x00;
  306.         PStrCat( sTemp, "¥p メ");
  307.         PStrCat( sTemp, pstr);
  308.         PStrCat( sTemp, "¥pモ");
  309.     }
  310.     else
  311.     {
  312.         PStrCpy( sTemp, pstr );
  313.     }
  314.     
  315.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  316.     /*
  317.      * OJO: should adjust strlen to item rect...
  318.      */
  319.     SetDialogItemText( itemHandle, sTemp );
  320. }
  321.  
  322. static void DisableDItem( DialogPtr DlgPtr, short item)
  323. {
  324.     short        itemType;
  325.     Handle        itemHandle;
  326.     Rect        itemRect;
  327.  
  328.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  329.     HiliteControl( (ControlHandle) itemHandle, 255 );
  330. }
  331.  
  332. static void EnableDItem( DialogPtr DlgPtr, short item)
  333. {
  334.     short        itemType;
  335.     Handle        itemHandle;
  336.     Rect        itemRect;
  337.  
  338.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  339.     HiliteControl( (ControlHandle) itemHandle, 0 );
  340. }
  341. /******************************************************************************/
  342.  
  343. static void DoItem(    DialogPtr DlgPtr, short item,
  344.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs, AliasHandle *FldrAlias )
  345.  
  346. {
  347.     short        itemType;
  348.     Handle        itemHandle;
  349.     Rect        itemRect;
  350.     short        value=-1;
  351.     Str255        sTemp;
  352.     
  353.     extern Boolean SFGetFolder(FSSpec *fSpec);
  354.     FSSpec        fSpec;
  355.     
  356.     
  357.     
  358.     GetDialogItem( DlgPtr, item, &itemType, &itemHandle, &itemRect);
  359.     
  360.     switch( myDlgInfo->Selection )
  361.     {
  362.         case pmPrefgzip:
  363.                 
  364.         switch( item - myDlgInfo->BaseDITL )
  365.         {
  366.             case kPrefgzip_Force:
  367.                 
  368.                 value = thePrefs->gzip.Force = !thePrefs->gzip.Force;
  369.                 break;
  370.                 
  371.             case kPrefgzip_NoName:
  372.             
  373.                 value = thePrefs->gzip.NoName = !thePrefs->gzip.NoName;
  374.                 
  375.                 if ( value && thePrefs->gzip.Name )
  376.                 {
  377.                     SetItemValue( DlgPtr, kPrefgzip_Name + myDlgInfo->BaseDITL, FALSE);
  378.                     thePrefs->gzip.Name = FALSE;
  379.                 }
  380.                     
  381.                 break;
  382.                 
  383.             case kPrefgzip_Name:
  384.     
  385.                 value = thePrefs->gzip.Name = !thePrefs->gzip.Name;
  386.     
  387.                 if ( value && thePrefs->gzip.NoName )
  388.                 {
  389.                     SetItemValue( DlgPtr, kPrefgzip_NoName + myDlgInfo->BaseDITL, FALSE);
  390.                     thePrefs->gzip.NoName = FALSE;
  391.                 }
  392.     
  393.                 break;
  394.     
  395.             case kPrefgzip_Custom:
  396.             
  397.                 value = thePrefs->gzip.UseCustomSuffix = !thePrefs->gzip.UseCustomSuffix;
  398.                 
  399.                 if ( value )
  400.                 {
  401.                     ShowDialogItem( DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL);
  402.                     EnableDItem( DlgPtr, kPrefgzip_GunSuff + myDlgInfo->BaseDITL);
  403.                 }
  404.                 else
  405.                 {
  406.                     HideDialogItem( DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL);
  407.                     DisableDItem( DlgPtr, kPrefgzip_GunSuff + myDlgInfo->BaseDITL);
  408.                 }
  409.                 
  410.                 break;
  411.                 
  412.             case kPrefgzip_GunSuff:
  413.             
  414.                 value = thePrefs->gzip.GunzipSuffix = !thePrefs->gzip.GunzipSuffix;
  415.                 break;
  416.                 
  417.             case kPrefgzip_Up:
  418.             
  419.                 if ( thePrefs->gzip.Level < 9 )
  420.                 {
  421.                     thePrefs->gzip.Level ++;
  422.                     InvertRect(&itemRect);
  423.                     while (StillDown())
  424.                         ;
  425.                     InvertRect(&itemRect);
  426.                     GetDialogItem( DlgPtr, kPrefgzip_Level + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  427.                     NumToString( (long)thePrefs->gzip.Level, sTemp );
  428.                     SetDialogItemText(itemHandle,sTemp);
  429.                 }
  430.                 break;
  431.                 
  432.             case kPrefgzip_Down:
  433.             
  434.                 if ( thePrefs->gzip.Level > 1 )
  435.                 {
  436.                     thePrefs->gzip.Level --;
  437.                     InvertRect(&itemRect);
  438.                     while (StillDown())
  439.                         ;
  440.                     InvertRect(&itemRect);
  441.                     GetDialogItem( DlgPtr, kPrefgzip_Level + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  442.                     NumToString( (long)thePrefs->gzip.Level, sTemp );
  443.                     SetDialogItemText(itemHandle,sTemp);
  444.                 }
  445.                 break;
  446.         }
  447.         break;
  448.         
  449.         case pmPrefcomp:
  450.         switch( item - myDlgInfo->BaseDITL )
  451.         {
  452.             case kPrefComp_Keys:
  453.                 value = thePrefs->Compress.Keys = !thePrefs->Compress.Keys;
  454.                 break;
  455.             case kPrefComp_IC:
  456.                 value = thePrefs->Compress.IC = !thePrefs->Compress.IC;
  457.                 if ( thePrefs->Compress.IC )
  458.                 {
  459.                     EnableDItem( DlgPtr, kPrefComp_ASCII + myDlgInfo->BaseDITL );
  460.                     EnableDItem( DlgPtr, kPrefComp_NotMB + myDlgInfo->BaseDITL );
  461.                 }
  462.                 else
  463.                 {
  464.                     DisableDItem( DlgPtr, kPrefComp_ASCII + myDlgInfo->BaseDITL );
  465.                     DisableDItem( DlgPtr, kPrefComp_NotMB + myDlgInfo->BaseDITL );
  466.                 }    
  467.     
  468.                 break;
  469.             case kPrefComp_ASCII:
  470.                 value = thePrefs->Compress.IC_ASCII = !thePrefs->Compress.IC_ASCII;
  471.                 break;
  472.             case kPrefComp_NotMB:
  473.                 value = thePrefs->Compress.IC_NotMB = !thePrefs->Compress.IC_NotMB;
  474.                 break;
  475.             case kPrefComp_RFPopup:
  476.                 GetItemValue( DlgPtr, item, &(thePrefs->Compress.ResFork));
  477.                 break;
  478.             case kPrefComp_ModePopup:
  479.                 if ( GetItemValue( DlgPtr, item, &(thePrefs->Compress.Mode)))
  480.                 {
  481.                     if ( thePrefs->Compress.Mode == pmPrefComp_MBin )
  482.                         ShowDialogItem( DlgPtr, kPrefComp_ModeA + myDlgInfo->BaseDITL);
  483.                     else
  484.                         HideDialogItem( DlgPtr, kPrefComp_ModeA + myDlgInfo->BaseDITL);
  485.                 }
  486.                 break;
  487.             case kPrefComp_ModeA:
  488.                 value = thePrefs->Compress.Mode_a = !thePrefs->Compress.Mode_a;
  489.                 break;
  490.         }
  491.         break;
  492.                             
  493.         
  494.         case pmPrefdeco:
  495.         switch( item - myDlgInfo->BaseDITL )
  496.         {
  497.             case kPrefDeco_Keys:
  498.                 value = thePrefs->Decompress.Keys = !thePrefs->Decompress.Keys;
  499.                 break;
  500.             case kPrefDeco_IC:
  501.                 value = thePrefs->Decompress.IC = !thePrefs->Decompress.IC;
  502.                 
  503.                 if ( value && thePrefs->Decompress.Fetch )
  504.                 {
  505.                     SetItemValue( DlgPtr, kPrefDeco_Fetch + myDlgInfo->BaseDITL, FALSE);
  506.                     thePrefs->Decompress.Fetch = FALSE;
  507.                 }
  508.                 break;
  509.                 
  510.             case kPrefDeco_Fetch:
  511.                 value = thePrefs->Decompress.Fetch = !thePrefs->Decompress.Fetch;
  512.     
  513.                 if ( value && thePrefs->Decompress.IC )
  514.                 {
  515.                     SetItemValue( DlgPtr, kPrefDeco_IC + myDlgInfo->BaseDITL, FALSE);
  516.                     thePrefs->Decompress.IC = FALSE;
  517.                 }
  518.     
  519.                 break;
  520.             case kPrefDeco_MB:
  521.                 value = thePrefs->Decompress.TryMB = !thePrefs->Decompress.TryMB;
  522.                 break;
  523.             case kPrefDeco_MPopup:
  524.                 GetItemValue( DlgPtr, item, &(thePrefs->Decompress.Mode));
  525.                 break;
  526.             default:
  527.                 break;
  528.         }
  529.         break;
  530.     
  531.         case pmPreffold:
  532.         switch( item - myDlgInfo->BaseDITL )
  533.         {
  534.             case kPrefFold_FNot:
  535.             case kPrefFold_FFold:
  536.             case kPrefFold_FAll:
  537.             
  538.                 SetItemValue( DlgPtr, thePrefs->Folder.RecurseMode + myDlgInfo->BaseDITL, 0 );
  539.                 thePrefs->Folder.RecurseMode = item - myDlgInfo->BaseDITL;
  540.                 value = 1;
  541.                 break;
  542.                 
  543.             case kPrefFold_UseDest:
  544.             
  545.                 /*
  546.                  * SFGetFolder
  547.                  */
  548.                  
  549.                 SetItemText( DlgPtr, kPrefFold_Dest + myDlgInfo->BaseDITL, "¥p", FALSE);
  550.                 
  551.                 if (!thePrefs->Folder.UseDestFolder)
  552.                 {
  553.                     if ( SFGetFolder(&fSpec) )
  554.                     {
  555.                         if ((*FldrAlias != gOriginalAliasHdl) && ( *FldrAlias != nil ))
  556.                             DisposeHandle((Handle) *FldrAlias);
  557.                             
  558.                         if ( noErr != (err=NewAlias(nil, &fSpec, FldrAlias)) )
  559.                         {
  560.                             *FldrAlias = nil;
  561.                             
  562.                             DoError(SYS_ERR,INFO_ERR,GetErrFmt(GENERIC, NOT_ALIAS));                            
  563.                             
  564.                         }
  565.                         else
  566.                         {
  567.                             value = thePrefs->Folder.UseDestFolder = TRUE;
  568.                             SetItemText( DlgPtr, kPrefFold_Dest + myDlgInfo->BaseDITL,
  569.                                     fSpec.name, TRUE);
  570.                         }
  571.                     }
  572.                 }
  573.                 else
  574.                     value = thePrefs->Folder.UseDestFolder = FALSE;
  575.  
  576.                     
  577.                     
  578.                 break;
  579.         }
  580.         break;
  581.         
  582.         case pmPrefmisc:
  583.         switch( item - myDlgInfo->BaseDITL )
  584.         {
  585.             case kPrefMisc_KeepOrig:
  586.                 value = thePrefs->Misc.KeepOriginal = !thePrefs->Misc.KeepOriginal;
  587.                 break;
  588.             case kPrefMisc_Beep:
  589.                 value = thePrefs->Misc.BeepWhenDone = !thePrefs->Misc.BeepWhenDone;
  590.                 break;
  591.             case kPrefMisc_Quit:
  592.                 value = thePrefs->Misc.QuitWhenDone = !thePrefs->Misc.QuitWhenDone;
  593.                 break;
  594.             case kPrefMisc_Keys:
  595.                 value = thePrefs->Misc.Keys = !thePrefs->Misc.Keys;
  596.                 break;
  597.             case kPrefMisc_SelPopup:
  598.                 GetItemValue( DlgPtr, item, &(thePrefs->Misc.DefaultOp));
  599.                 break;
  600.             case kPrefMisc_Reset:
  601.                 thePrefs->SavedPos = TRUE;
  602.                 thePrefs->SavedPoint.v = 80;
  603.                 thePrefs->SavedPoint.h = 80;
  604.                 break;
  605.         }
  606.         
  607.         default:
  608.             break;
  609.     }
  610.     if (( itemType & ctrlItem ) && ( value != -1 ))
  611.         SetControlValue( (ControlHandle) itemHandle, value );
  612. }
  613.  
  614. static void SetItems(    DialogPtr DlgPtr,
  615.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs, AliasHandle *FldrAlias )
  616. {
  617.     short        itemType;
  618.     Handle        itemHandle;
  619.     Rect        itemRect;
  620.     Str255        sTemp;
  621.  
  622.     switch( myDlgInfo->Selection )
  623.     {
  624.         case pmPrefgzip:
  625.             
  626.             SetItemValue( DlgPtr, kPrefgzip_Force + myDlgInfo->BaseDITL, thePrefs->gzip.Force);
  627.             SetItemValue( DlgPtr, kPrefgzip_NoName + myDlgInfo->BaseDITL, thePrefs->gzip.NoName);
  628.             SetItemValue( DlgPtr, kPrefgzip_Name + myDlgInfo->BaseDITL, thePrefs->gzip.Name);
  629.             SetItemValue( DlgPtr, kPrefgzip_Custom + myDlgInfo->BaseDITL, thePrefs->gzip.UseCustomSuffix);
  630.             if ( thePrefs->gzip.UseCustomSuffix )
  631.             {
  632.                 ShowDialogItem( DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL);
  633.                 EnableDItem( DlgPtr, kPrefgzip_GunSuff + myDlgInfo->BaseDITL);
  634.             }
  635.             else
  636.             {
  637.                 HideDialogItem( DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL);
  638.                 DisableDItem( DlgPtr, kPrefgzip_GunSuff + myDlgInfo->BaseDITL);
  639.             }
  640.             SetItemValue( DlgPtr, kPrefgzip_GunSuff + myDlgInfo->BaseDITL, thePrefs->gzip.GunzipSuffix);
  641.             GetDialogItem( DlgPtr, kPrefgzip_Level + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  642.             NumToString( (long)thePrefs->gzip.Level, sTemp );
  643.             SetDialogItemText(itemHandle,sTemp);
  644.             GetDialogItem(DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  645.             SetDialogItemText(itemHandle, thePrefs->gzip.Suffix);
  646.             if(thePrefs->gzip.Suffix[0]!=0x00)
  647.             SelectDialogItemText(DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL, 0, 32767);
  648.             break;
  649.             
  650.         case pmPrefcomp:
  651.  
  652.             SetItemValue( DlgPtr, kPrefComp_Keys + myDlgInfo->BaseDITL, thePrefs->Compress.Keys);
  653.             SetItemValue( DlgPtr, kPrefComp_IC + myDlgInfo->BaseDITL, thePrefs->Compress.IC);
  654.             SetItemValue( DlgPtr, kPrefComp_ASCII + myDlgInfo->BaseDITL, thePrefs->Compress.IC_ASCII);
  655.             SetItemValue( DlgPtr, kPrefComp_NotMB + myDlgInfo->BaseDITL, thePrefs->Compress.IC_NotMB);
  656.             SetItemValue( DlgPtr, kPrefComp_RFPopup + myDlgInfo->BaseDITL, thePrefs->Compress.ResFork);
  657.             SetItemValue( DlgPtr, kPrefComp_ModePopup + myDlgInfo->BaseDITL, thePrefs->Compress.Mode);
  658.             SetItemValue( DlgPtr, kPrefComp_ModeA + myDlgInfo->BaseDITL, thePrefs->Compress.Mode_a);
  659.             
  660.             if ( thePrefs->Compress.IC )
  661.             {
  662.                 EnableDItem( DlgPtr, kPrefComp_ASCII + myDlgInfo->BaseDITL );
  663.                 EnableDItem( DlgPtr, kPrefComp_NotMB + myDlgInfo->BaseDITL );
  664.             }
  665.             else
  666.             {
  667.                 DisableDItem( DlgPtr, kPrefComp_ASCII + myDlgInfo->BaseDITL );
  668.                 DisableDItem( DlgPtr, kPrefComp_NotMB + myDlgInfo->BaseDITL );
  669.             }    
  670.             
  671.             if ( thePrefs->Compress.Mode == pmPrefComp_MBin )
  672.                 ShowDialogItem( DlgPtr, kPrefComp_ModeA + myDlgInfo->BaseDITL);
  673.             else
  674.                 HideDialogItem( DlgPtr, kPrefComp_ModeA + myDlgInfo->BaseDITL);
  675.             
  676.             break;
  677.  
  678.         case pmPrefdeco:
  679.         
  680.             SetItemValue( DlgPtr, kPrefDeco_Keys + myDlgInfo->BaseDITL, thePrefs->Decompress.Keys);
  681.             SetItemValue( DlgPtr, kPrefDeco_IC + myDlgInfo->BaseDITL, thePrefs->Decompress.IC);
  682.             SetItemValue( DlgPtr, kPrefDeco_Fetch + myDlgInfo->BaseDITL, thePrefs->Decompress.Fetch);
  683.             SetItemValue( DlgPtr, kPrefDeco_MB + myDlgInfo->BaseDITL, thePrefs->Decompress.TryMB);
  684.             
  685.             OSTypeToStr255( sTemp, &thePrefs->Decompress.TextCreator );
  686.             GetDialogItem(DlgPtr, kPrefDeco_CText + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  687.             SetDialogItemText(itemHandle, sTemp);
  688.             SelectDialogItemText(DlgPtr, kPrefDeco_CText + myDlgInfo->BaseDITL, 0, 32767);
  689.  
  690.             OSTypeToStr255( sTemp, &thePrefs->Decompress.BinType );
  691.             GetDialogItem(DlgPtr, kPrefDeco_TBin + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  692.             SetDialogItemText(itemHandle, sTemp);
  693.             
  694.             OSTypeToStr255( sTemp, &thePrefs->Decompress.BinCreator );
  695.             GetDialogItem(DlgPtr, kPrefDeco_CBin + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  696.             SetDialogItemText(itemHandle, sTemp);
  697.  
  698.             SetItemValue( DlgPtr, kPrefDeco_MPopup + myDlgInfo->BaseDITL, thePrefs->Decompress.Mode);
  699.         
  700.             break;
  701.             
  702.         case pmPreffold:
  703.         
  704.             SetItemValue( DlgPtr, kPrefFold_FNot + myDlgInfo->BaseDITL, 0 );
  705.             SetItemValue( DlgPtr, kPrefFold_FFold + myDlgInfo->BaseDITL, 0 );
  706.             SetItemValue( DlgPtr, kPrefFold_FAll + myDlgInfo->BaseDITL, 0 );
  707.             SetItemValue( DlgPtr, thePrefs->Folder.RecurseMode + myDlgInfo->BaseDITL, 1 );
  708.  
  709.             SetItemText( DlgPtr, kPrefFold_Dest + myDlgInfo->BaseDITL, "¥p", FALSE);
  710.             
  711.             if (( thePrefs->Folder.UseDestFolder ) && (*FldrAlias!=nil))
  712.             {
  713.                 FSSpec    fSpec;
  714.                 Boolean    changedFlag;
  715.                 
  716.                 if( noErr == ResolveAlias(nil, *FldrAlias, &fSpec, &changedFlag))
  717.                     SetItemText( DlgPtr, kPrefFold_Dest + myDlgInfo->BaseDITL, fSpec.name, TRUE);
  718.                 else
  719.                 {
  720.                     thePrefs->Folder.UseDestFolder = FALSE;
  721.                 }
  722.             }
  723.             else
  724.             {
  725.                 thePrefs->Folder.UseDestFolder = FALSE;
  726.             }
  727.             
  728.             SetItemValue( DlgPtr, kPrefFold_UseDest + myDlgInfo->BaseDITL, thePrefs->Folder.UseDestFolder );
  729.  
  730.  
  731.             break;
  732.             
  733.         case pmPrefmisc:
  734.         
  735.             SetItemValue( DlgPtr, kPrefMisc_KeepOrig + myDlgInfo->BaseDITL, thePrefs->Misc.KeepOriginal);
  736.             SetItemValue( DlgPtr, kPrefMisc_Beep + myDlgInfo->BaseDITL, thePrefs->Misc.BeepWhenDone);
  737.             SetItemValue( DlgPtr, kPrefMisc_Quit + myDlgInfo->BaseDITL, thePrefs->Misc.QuitWhenDone);
  738.             SetItemValue( DlgPtr, kPrefMisc_Keys + myDlgInfo->BaseDITL, thePrefs->Misc.Keys);
  739.             SetItemValue( DlgPtr, kPrefMisc_SelPopup + myDlgInfo->BaseDITL, thePrefs->Misc.DefaultOp);
  740.             break;
  741.         
  742.         default:
  743.             break;
  744.     }
  745. }
  746.  
  747. /* Get editText fields */
  748.  
  749. static Boolean GetItems(    DialogPtr DlgPtr,
  750.                     DlgInfoPtr myDlgInfo, PrefsTypePtr thePrefs )
  751. {
  752.     short        itemType;
  753.     Handle        itemHandle;
  754.     Rect        itemRect;
  755.     Str255        sTemp;
  756.     Boolean        result;
  757.     
  758.     result = TRUE;
  759.  
  760.     switch( myDlgInfo->Selection )
  761.     {
  762.         case pmPrefgzip:
  763.             GetDialogItem(DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  764.             
  765.             if (thePrefs->gzip.UseCustomSuffix)
  766.             {
  767.                 GetDialogItemText(itemHandle, thePrefs->gzip.Suffix);
  768.                 
  769.                 if ((thePrefs->gzip.Suffix[0] == 0) || (thePrefs->gzip.Suffix[0] > MAX_SUFFIX ))
  770.                 {
  771.                     DoError(INPUT_ERR,INFO_ERR,GetErrFmt(USER_ERROR,BAD_SUFFIX), 1, MAX_SUFFIX);
  772.                     if (thePrefs->gzip.Suffix[0] != 0)
  773.                         SelectDialogItemText(DlgPtr, kPrefgzip_Suffix + myDlgInfo->BaseDITL,0,32767);
  774.                     result = FALSE;
  775.                 }
  776.             }
  777.             break;
  778.             
  779.         case pmPrefcomp:
  780.             break;
  781.             
  782.         case pmPrefdeco:
  783.         
  784.             GetDialogItem(DlgPtr, kPrefDeco_CText + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  785.             GetDialogItemText(itemHandle, sTemp);
  786.             
  787.             if (sTemp[0] != 4)
  788.             {
  789.                 DoError(INPUT_ERR,INFO_ERR,GetErrFmt(USER_ERROR,BAD_CTEXT));
  790.                 if (sTemp[0] != 0)
  791.                         SelectDialogItemText(DlgPtr, kPrefDeco_CText + myDlgInfo->BaseDITL,0,32767);
  792.                 result = FALSE;
  793.                 break;
  794.             }
  795.             
  796.             thePrefs->Decompress.TextCreator = Str255ToOSType( sTemp );
  797.             
  798.             GetDialogItem(DlgPtr, kPrefDeco_TBin + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  799.             GetDialogItemText(itemHandle, sTemp);
  800.             
  801.             if (sTemp[0] != 4)
  802.             {
  803.                 DoError(INPUT_ERR,INFO_ERR,GetErrFmt(USER_ERROR,BAD_TBIN));
  804.                 if (sTemp[0] != 0)
  805.                         SelectDialogItemText(DlgPtr, kPrefDeco_TBin + myDlgInfo->BaseDITL,0,32767);
  806.                 result = FALSE;
  807.                 break;
  808.             }
  809.             
  810.             thePrefs->Decompress.BinType = Str255ToOSType( sTemp );
  811.             
  812.             GetDialogItem(DlgPtr, kPrefDeco_CBin + myDlgInfo->BaseDITL, &itemType, &itemHandle, &itemRect);
  813.             GetDialogItemText(itemHandle, sTemp);
  814.             
  815.             if (sTemp[0] != 4)
  816.             {
  817.                 DoError(INPUT_ERR,INFO_ERR,GetErrFmt(USER_ERROR,BAD_CBIN));
  818.                 if (sTemp[0] != 0)
  819.                         SelectDialogItemText(DlgPtr, kPrefDeco_CBin + myDlgInfo->BaseDITL,0,32767);
  820.                 result = FALSE;
  821.                 break;
  822.             }
  823.  
  824.             thePrefs->Decompress.BinCreator = Str255ToOSType( sTemp );
  825.  
  826.             break;
  827.             
  828.         case pmPreffold:
  829.             break;
  830.             
  831.         case pmPrefmisc:
  832.             break;
  833.             
  834.         default:
  835.             break;
  836.     }        
  837.     return result;
  838. }
  839.  
  840.  
  841. /******************************************************************************/
  842.  
  843. PrefsType DefaultPrefs =
  844. {
  845.     kCurrentPrefsTypeVers,
  846.     TRUE,                /* SavedPos */
  847.     0x00,
  848.     {
  849.         80,                /* v */
  850.         80                /* h */
  851.     },
  852.     {
  853.         FALSE,            /* Force */
  854.         FALSE,            /* NoName */
  855.         TRUE,            /* Name */
  856.         FALSE,            /* UseCustomSuffix */
  857.         FALSE,            /* GunzipSuffix */
  858.         0x00,
  859.         6,                /* Level */
  860.         "¥p"            /* Suffix */
  861.     },
  862.     {
  863.         TRUE,            /* Keys */
  864.         TRUE,            /* IC */
  865.         FALSE,            /* IC_ASCII */
  866.         FALSE,            /* IC_NotMB */
  867.         kComp_RFAsk,    /* ResFork */
  868.         kComp_MBin,        /* Mode */
  869.         TRUE,            /* Modea */
  870.     },
  871.     {
  872.         TRUE,            /* Keys */
  873.         TRUE,            /* IC */
  874.         FALSE,            /* Fetch */
  875.         TRUE,            /* TryMB */
  876.         'ttxt',            /* TextCreator */
  877.         '¥?¥?¥?¥?',        /* BinType */
  878.         '¥?¥?¥?¥?',        /* BinCreator */
  879.         kDeco_MBin        /* Default Mode */
  880.     },
  881.     {
  882.         kFold_FAll,        /* RecurseMode */
  883.         FALSE,            /* UseDestFoレレレ|□òレレレレユホホホホホホホヘロレテ□舒マホホホホホヘルレレレレレレレš゚ホホホホホホホホホホホホホホホホホホホホホホホホヘæ1□ンホホホホホホホホホレ□,:ョ`ミホホホホホホホホホホホホロレァ□涅ホホホホホホホホホホメレ゙q/慂ホホホホホホホフìò珮矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣矣